// File:       hoistbp.c++
// Version:    1.01
// Author:     (c) Miles Sabin, 1997
// Purpose:    hoisted binary predicate

// Change log:
//  13/01/97   v. 1.00
//  23/01/97   Singletonized.
//  31/01/97   member_size renamed to member_offset and alignment problems
//               sorted out.
//  23/02/97   Split HoistComparator off from HoistHelper to remove
//               requirement for contained classes to define  operator==()
//               and operator<() whereever possible.
//             member_offset() replaced by member_base_offset().
//  01/04/97   Added HoistUnaryPredicateProtocol.
//             Added HoistBinaryPredicateProtocol.
//  02/04/97   v. 1.01
//             Split off into separate translation unit.

#include "functional.h"
#include "hoistbp.h"

#include "newcasts.h"
#include "tpltutil.h"


// Implementation of HoistBinaryPredicate<BinaryPredicate, T>

template<class BinaryPredicate, class T>
HoistBinaryPredicate<BinaryPredicate, T>::~HoistBinaryPredicate()
  {}

template<class BinaryPredicate, class T>
bool HoistBinaryPredicate<BinaryPredicate, T>::operator()(void const* x, void const* y) const
  {
    // const_cast needed because CFront may think that pred_ is a non-const mfn
    return const_cast(HoistBinaryPredicate<BinaryPredicate _ T>*, this)->pred_(*reinterpret_cast(T const*, x), *reinterpret_cast(T const*, y));
  }


// Implementation of HoistBinaryPredicate<BinaryPredicate, T> free fns

template<class T>
HoistBinaryPredicateProtocol& get_hoist_equal_to_comparator(T*)
{
  static equal_to<T> comparator;
  static HoistBinaryPredicate<equal_to<T>, T> singleton(comparator);
  return singleton;
}

template<class T>
HoistBinaryPredicateProtocol& get_hoist_less_comparator(T*)
{
  static less<T> comparator;
  static HoistBinaryPredicate<less<T>, T> singleton(comparator);
  return singleton;
}
